<template>
  <div class="auth-form">
    <h3 class="auth-title">{{ title }}</h3>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button block type="info" native-type="submit" :color="btnColor"
          >提交</van-button
        >
      </div>
    </van-form>
    <div class="auth-link">
      <router-link :to="linkPath">{{ linkName }}</router-link>
    </div>
  </div>
</template>

<script>
export default {
  name: "AuthForm",
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    onSubmit(values) {
      // console.log("submit", values);
      this.$emit("onSubmit", values);
    },
  },
  props: {
    btnColor: {
      type: String,
      default: "#fa6d1d",
    },
    title: {
      type: String,
      default: "面经登录",
    },
    linkName: {
      type: String,
      default: "注册账号",
    },
    linkPath: {
      type: String,
      default: "/register",
    },
  },
};
</script>

<style lang="less" scoped>
.auth-form {
  margin-top: 30px;
  .auth-title {
    text-align: center;
  }
  .auth-link {
    display: flex;
    justify-content: end;
    padding: 0 20px;
    a {
      color: #069;
      font-size: 3.2vw;
    }
  }
}
</style>
